<template>
    <!-- 查询表单 -->
    <div class="search-form">
        <el-card class="search-card">
            <div class="search-container">
                <div class="search-fields">
                    <div class="field-row">
                        <!-- <el-button type="success" class="!ml-0" plain @click="dialogFormVisible = true">新增</el-button> -->
                        <el-input v-model="page.Bomname" placeholder="请输入物料名称" class="search-input" clearable />
                    </div>
                </div>
                <div class="search-actions">
                    <el-button type="primary" @click="list" class="search-btn">
                        <el-icon>
                            <Search />
                        </el-icon>
                        查询
                    </el-button>
                    <el-button type="info" @click="clearSearch" class="clear-btn">
                        <el-icon>
                            <Close />
                        </el-icon>
                        重置
                    </el-button>
                </div>
            </div>
        </el-card>
    </div>
    <el-table :data="tableData" style="width: 100%">
        <el-table-column fixed type="index" label="序号" width="70" />
        <el-table-column prop="bomCode" label="物料编码" width="100" />
        <el-table-column prop="bomName" label="物料名称" width="100" />
        <el-table-column prop="version" label="物料版本" width="80" />
        <el-table-column prop="bomLevel" label="物料等级" width="100" />
        <el-table-column prop="useQty" label="使用数量" width="120" />
        <el-table-column prop="bomMsg" label="物料备注" width="120" />
        <el-table-column prop="prodCode" label="工单编码" width="150" />
        <el-table-column prop="prodStatus" label="工单名称" width="120" />
        <el-table-column prop="prodQty" label="工单数量" width="120" />
        <el-table-column prop="receiveSum" label="需要出库数量" width="120" />
        <el-table-column fixed="right" label="操作" min-width="120">
            <template #default="script">
                <el-button link type="primary" size="small" @click="handleClick">
                    删除
                </el-button>
                <el-button link type="primary" size="small">修改</el-button>
                <el-button link type="primary" size="small" @click="OutAdd(script.row)">出库 </el-button>
            </template>
        </el-table-column>
    </el-table>
</template>

<script lang="ts" setup>
import Maxios from '@/Http/MesHelp';
import { onMounted, ref, reactive } from 'vue';
import { ElMessage, ElMessageBox } from 'element-plus'

const handleClick = () => {
    console.log('click')
}

const tableData = ref([])

const page = ref({
    PageIndex: 1,
    PageSize: 5,
    Bomname: "",
    count: 0,
    page: 0
})

const list = () => {
    Maxios.get("/api/Storehouse/ReceiveShow", { params: page.value }).then(res => {
        tableData.value = res.data.data.list
        page.value.count = res.data.count
        page.value.page = res.data.page
    })
}

// 清空搜索条件
const clearSearch = () => {
    page.value.Bomname = ""
    page.value.PageIndex = 1
    list()
}

const User = reactive({
    Name: localStorage.getItem("userNickname") || ''
})
//材料检测 出库方法
const waremData: any = ref({
    "OutName": "",
    "OutSum": 0,
    "OutThing": "",
    "OutCode": "",
    "OutStates": "",
    "WareId": 0,
    "FinishId": 0,
    "IncomingCode": "",
    "FinishCode": "",
    "AddProp": User.Name
})
const OutAdd = (data: any) => {
    //alert("asdsadasdas")
    console.log("asd", data)
    waremData.value.OutName = "材料出库"
    waremData.value.OutSum = data.receiveSum
    waremData.value.OutThing = data.bomName
    waremData.value.IncomingCode = data.prodCode
    if (waremData.value.OutThing == "塑料") {
        waremData.value.WareId = 1
    }
    if (waremData.value.outThing == "芯片") {
        waremData.value.wareId = 4
    }
    if (waremData.value.outThing == "电缆") {
        waremData.value.wareId = 3
    }
    if (waremData.value.outThing == "音头") {
        waremData.value.wareId = 2
    }

    console.log(waremData.value);

    Maxios.post("/api/Storehouse/OutorinAdd", waremData.value).then(res => {
        if (res.data.code == 200) {
            ElMessage.success("从库成功")
            list()
        }
        else {
            ElMessage.error(res.data.message)
            list()
        }
    })
}


onMounted(() => {
    list()//显示
})
</script>

<style scoped>
.search-form {
    margin-bottom: 20px;
}

.search-card {
    background: #f5f5f5;
    border-radius: 8px;
}

.search-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
}

.search-fields {
    flex: 1;
}

.field-row {
    display: flex;
    gap: 16px;
    align-items: center;
}


.search-actions {
    display: flex;
    gap: 12px;
    align-items: center;
}


.search-input {
    width: 200px;
}

.search-btn {
    border-radius: 6px;
}

.clear-btn {
    background: #f0f0f0;
    border: 1px solid #d9d9d9;
    color: #666;
    border-radius: 6px;
}
</style>